package com.wgy.day37Stream流.获取流;

import java.util.*;
import java.util.stream.Stream;

/*
java.util.stream.Stream<T>:是java 8新加入的最常用的流接口
获取一个流的方法:
  1.所有Collection集合都可以通过stream默认方法获取流
       default Stream<E> stream():

  2.Stream接口的静态方法of可以获取数组对应的流
       static <T> Stream<T> of(T...values)
          参数:是一个可变参数,那么我们就可以传递一个数组

*/
public class Demo02GetStream {
    public static void main(String[] args) {
        //把集合转换为Stream流
        List<String> list = new ArrayList<>();
        Stream<String> stream = list.stream();

        Set<String> set=new HashSet<>();
        Stream<String> stream1 = set.stream();

        Map<String,String> map=new HashMap<>();
        //获取键值对,存储到一个Set集合中
        Set<Map.Entry<String, String>> entries = map.entrySet();
        Stream<Map.Entry<String, String>> stream2 = entries.stream();

        //获取键,存储到一个set集合中
        Set<String> keySet = map.keySet();
        Stream<String> stream3 = keySet.stream();

        //获取value值存储到一个Collection集合中
        Collection<String> values = map.values();
        Stream<String> stream4 = values.stream();

        //把数组转换为Stream流
        Stream<Integer> stream5 = Stream.of(1, 2, 3, 4, 5);

        //把可变参数转换为Stream流
        String [] arr={"1","2","3","4","5"};
        Stream<String> stream6 = Stream.of(arr);
        Integer[] arr2={1,2,3,4,5};
        Stream<Integer> stream7 = Stream.of(arr2);



    }
}
